#!/usr/bin/perl
# file: daytime_cli2.pl
use strict;
use Socket;
use constant DEFAULT_ADDR => '127.0.0.1';
my $packed_addr = gethostbyname(shift || DEFAULT_ADDR) or die
    "Can't look up host: $!";
# 查找主机地址，并将主机名称转换为压缩的ip地址。    
my $protocal = getprotobyname('tcp');
#检索tcp的协议号
my $port = getservbyname('daytime', 'tcp') or die
    "Can't look up port: $!";
#查找端口号    
print "daytime port is $port\n";
my $destination = sockaddr_in($port, $packed_addr);
socket(SOCK, PF_INET, SOCK_STREAM, $protocal) or die
    "Can't make socket: $!";
connect(SOCK, $destination) or die
    "Can't connect : $!";
select SOCK; $| = 1; select STDOUT;
print <SOCK>;